﻿//-----------------------------------------------------------------------------------------//
//-     Writen by Raymond Honderdors
//-     2013-05-14
//-
//-     Code can be used as is, no warrenty
//-     https://solutionmanagementki.codeplex.com/
//-----------------------------------------------------------------------------------------//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AnalysisServices;
namespace SMK_SSAS
{
    /// <summary>
    /// 
    /// </summary>
    public class AMO_Database_Cube
    {
        private Microsoft.AnalysisServices.Cube amocube = null;
        private AMO_Database amodb = null;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Datebase"></param>
        /// <param name="CubeID"></param>
        public void SetAMODatabaseCube(AMO_Database Datebase, string CubeID)
        {

            if (Datebase != null)
            {
                AMO_Server Server = Datebase.AMOServer();
                if (Server.Isconnected())
                {
                    if (Datebase.amodatabase().Cubes.Contains(CubeID))
                    {
                        amocube = Datebase.amodatabase().Cubes.Find(CubeID);
                    }
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public AMO_Database AMODatabase()
        {
            if (amodb != null)
            {

                return amodb;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Microsoft.AnalysisServices.Cube amodcube()
        {
            if (amocube != null)
            {

                return amocube;

            }
            else
            {
                return null;
            }
        }        

        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubeActions()
        {
            if (amocube != null)
            {
                if (amocube.Actions.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubePermissions()
        {
            if (amocube != null)
            {
                if (amocube.CubePermissions.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubeDimensions()
        {
            if (amocube != null)
            {
                if (amocube.Dimensions.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubeKPIs()
        {
            if (amocube != null)
            {
                if (amocube.Kpis.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubeMdxScripts()
        {
            if (amocube != null)
            {
                if (amocube.MdxScripts.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubeMeasureGroups()
        {
            if (amocube != null)
            {
                if (amocube.MeasureGroups.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubePerspectives()
        {
            if (amocube != null)
            {
                if (amocube.Perspectives.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasCubeTranslations()
        {
            if (amocube != null)
            {
                if (amocube.Translations.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> Actions()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Action db in amocube.Actions)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubePermissions()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.CubePermission db in amocube.CubePermissions)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubeDimensions()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.CubeDimension db in amocube.Dimensions)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubeKPIs()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Kpi db in amocube.Kpis)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubeMdxScripts()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.MdxScript db in amocube.MdxScripts)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubeMeasureGroups()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.MeasureGroup db in amocube.MeasureGroups)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubePersectives()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Perspective db in amocube.Perspectives)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amocube.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> CubeTranslations()
        {
            if (amocube != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Translation db in amocube.Translations)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.Language.ToString();
                    amok.Name = db.Caption;
                    result.Add(amocube.Name + "\\" + db.Language.ToString(), amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
    }
}
